package com.xmsx.back.mapper.index;

import com.xmsx.back.pojo.Job;
import com.xmsx.back.pojo.Recruitment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.sql.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface RecruitmentMapper {

    /**
     * 获取tag列表
     *
     * @return
     */
    @Select("select distinct tag from tag")
    List<String> getTagList();

    /**
     * 统计某个tag的记录数
     *
     * @return
     */
    @Select("select count(1) from tag where tag = #{tag}")
    long countByTag(String tag);

    /**
     * 按tag按页查询
     *
     * @param params
     * @return
     */
    @Select("select distinct website, title, datetime, tags from tag natural join job where tag = #{tag} order by datetime desc, website desc limit #{page},#{size}")
    List<Recruitment> findByTagByPager(Map<String, Object> params);

    /**
     * 按关键词模糊查询
     *
     * @param keyword
     * @return
     */
    @Select("select count(1) from job where title like concat('%', #{keyword}, '%')")
    long countByKeyword(String keyword);

    /**
     * 按关键词按页查询
     *
     * @param params
     * @return
     */
    @Select("select * from job where title like concat('%', #{keyword}, '%') order by datetime desc, website desc limit #{page},#{size}")
    List<Recruitment> findByKeywordByPager(Map<String, Object> params);

    /**
     * 统计记录数
     *
     * @return
     */
    @Select("select count(1) from job")
    long count();

    /**
     * 按页查询
     *
     * @param params
     * @return
     */
    @Select("select * from job order by datetime desc, website desc limit #{page},#{size}")
    List<Recruitment> findByPager(Map<String, Object> params);

    /**
     * 爬虫用
     * 获取某个website的全部信息
     *
     * @param website
     * @return
     */
    @Select("select * from job where website = #{website}")
    Recruitment getByWebsite(String website);

    /**
     * 爬虫用
     * 插入tag记录
     *
     * @param tag
     * @param website
     */
    @Insert("insert into tag values (#{tag}, #{website})")
    void setTag(String tag, String website);

    /**
     * 爬虫用
     * 插入招聘信息记录
     *
     * @param website
     * @param title
     * @param datetime
     * @param tags
     */
    @Insert("insert into job values (#{website}, #{title}, #{datetime}, #{tags})")
    void setJob(String website, String title, Date datetime, String tags);
}
